home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 52 / Mac Magazin and MacEasy Magazine CD - Issue 52.iso / Updates / Stata 5.0 Ado-files / ado.sea / newado / stack.hlp < prev    next >
Text File  |  1998-11-22  |  4KB  |  139 lines

  1. .-
  2. help for ^stack^                             (updated STB-40; manual:  ^[R] stack^)
  3. .-
  4.  
  5. Stack data
  6. ----------
  7.  
  8.     ^stack^ varlist [^if^ exp] [^in^ range]^,^ { ^i^nto^(^newvars^)^ | ^g^roup^(^#^)^ }
  9.                      [ ^clear^ ^wi^de ]
  10.  
  11.  
  12. Description
  13. -----------
  14.  
  15. ^stack^ stacks variables in varlist vertically.  Consider
  16.  
  17.     . ^stack a b c d e f, into(g h)^
  18.  
  19. This would create a new dataset containing
  20.  
  21.         g      h           ^_stack^
  22.         ---------------------------
  23.         a      b             1            (_N observations)
  24.         c      d             2            (_N observations)
  25.         e      f             3            (_N observations)
  26.  
  27. The resulting dataset would have 3*_N observations.  The first _N observations
  28. would have all the data from variables a and b, the second _N observation all
  29. the data from c and d, and the third _N observations all the data from e and
  30. f.
  31.  
  32. ^stack^ also creates a new variable, ^_stack^, identifying the groups.
  33.  
  34. As another example, 
  35.  
  36.     . ^stack a b c d e f, into(g h i)^
  37.  
  38. would create a new dataset containing
  39.  
  40.         g      h      i    ^_stack^
  41.         ---------------------------
  42.         a      b      c      1            (_N observations)
  43.         d      e      f      2            (_N observations)
  44.  
  45. The number of variables specified by ^into()^ determine the number of groups
  46. formed.  ^into()^ may be specified with variable ranges, such as 
  47.  
  48.     . ^stack a b c d e f, into(v1-v3)^
  49.  
  50. as, of course, may the varlist 
  51.  
  52.     . ^stack a-f, into(v1-v3)^
  53.  
  54. The new variables formed may have the existing variables' names;
  55.  
  56.     . ^stack a b c d e f, into(a b)^
  57. and
  58.     . ^stack a b c d e f, into(a b c)^
  59.  
  60. make perfect sense.
  61.  
  62. When you want the new variables to have the same names as the variables in the
  63. first group, rather than specifying ^into()^, you may specify ^group()^.
  64. Equivalent to the above are
  65.  
  66.     . ^stack a b c d e f, group(2)^
  67. and
  68.     . ^stack a b c d e f, group(3)^
  69.  
  70. For instance, the latter command creates 
  71.  
  72.         a      b           ^_stack^
  73.         ---------------------------
  74.         a      b             1            (_N observations)
  75.         c      d             2            (_N observations)
  76.         e      f             3            (_N observations)
  77.  
  78.  
  79. Options
  80. -------
  81.  
  82. ^into(^newvars^)^ and ^group(^#^)^ are alternatives and you must specify one or the
  83.     other, but not both.
  84.  
  85. ^into(^newvars^)^ specifies the the names of the new variables to be created.
  86.     The implied number of groups is then v/n, where v is the number of 
  87.     varlist variables and n the number of ^into()^ variables.  For instance,
  88.  
  89.     . ^stack a b c d e f, into(v1 v2 v3)^
  90.  
  91.     implies two groups:  (a b c) and (d e f).  
  92.  
  93. ^group(^#^)^ specifies the number of groups and specifies that the new variables
  94.     are to be named according to the first # variables in varlist.  For
  95.     instance,
  96.  
  97.     . ^stack a b c d e f, group(2)^
  98.  
  99.     specifies that there are two groups and the new variables are to be called
  100.     a, b, and c.
  101.  
  102. ^clear^ indicates your understanding that the data in memory will be lost; if
  103.     not specified, you will be asked to confirm your intentions.
  104.  
  105. ^wide^ includes any of the original variables in varlist that are not specified
  106.     in newvars in the resulting dataset.
  107.  
  108.  
  109. Examples
  110. --------
  111.  
  112. See ^[R] stack^.  Here, we will give one mechanical example.
  113.  
  114.  . ^list^
  115.               a        b        c        d  
  116.    1.         1        2        3        4  
  117.    2.         5        6        7        8  
  118.  
  119.  . ^stack a b  c d, into(e f) clear^
  120.  
  121.  . ^list^
  122.               e        f    _stack  
  123.    1.         1        2         1  
  124.    2.         5        6         1  
  125.    3.         3        4         2  
  126.    4.         7        8         2  
  127.  
  128. That is, the new variable ^e^ is formed by stacking ^a^ and ^c^, while the new
  129. variable ^f^ is formed by stacking ^b^ and ^d^.  ^_stack^ is automatically created
  130. and set equal to 1 for the first (^a^,^b^) group and 2 for the second (^c^,^d^) 
  131. group.  
  132.  
  133.  
  134. Also see
  135. --------
  136.  
  137.  Manual:  ^[R] stack^
  138. On-line:  help for @reshape@, @xpose@
  139.